package com.example.controller.buyer;

import com.example.service.UserCollectService;
import com.example.vo.PageVo;
import com.example.vo.Result;
import io.swagger.v3.oas.annotations.Operation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description:
 * @Author: aimi
 * @Create: 2024-05-22
 **/
@RestController
@Slf4j
@RequestMapping("/buyer/collect")
public class UserCollectController {
    @Autowired
    private UserCollectService collectService;

    @PostMapping("/collectSpu/{spuId}")
    @Operation(summary = "收藏、取消收藏商品")
    public Result collectSpu(@PathVariable Long spuId,Integer operation){
        collectService.collectSpu(spuId,operation);
        return Result.ok();
    }

    @GetMapping("/collectSpuStatus")
    @Operation(summary = "获取收藏商品状态")
    public Result<Boolean> getCollectSpuStatus(Long spuId){
        boolean status = collectService.getCollectSpuStatus(spuId);
        return Result.ok(status);
    }

    @Operation(summary = "获取收藏商品分页数据")
    @GetMapping("/getSpuCollectPage")
    public Result<PageVo> getSpuCollectPage(@RequestParam(defaultValue = "1") Integer pageNo,
                                            @RequestParam(defaultValue = "10") Integer pageSize){
        PageVo pageVo = collectService.getSpuCollectPage(pageNo,pageSize);
        return Result.ok(pageVo);
    }

    @Operation(summary = "获取收藏店铺分页数据")
    @GetMapping("/getStoreCollectPage")
    public Result<PageVo> getStoreCollectPage(@RequestParam(defaultValue = "1") Integer pageNo,
                                            @RequestParam(defaultValue = "10") Integer pageSize){
        PageVo pageVo = collectService.getStoreCollectPage(pageNo,pageSize);
        return Result.ok(pageVo);
    }

    @PostMapping("/collectStore/{storeId}")
    @Operation(summary = "收藏、取消收藏店铺")
    public Result collectStore(@PathVariable Long storeId,Integer operation){
        collectService.collectStore(storeId,operation);
        return Result.ok();
    }

    @GetMapping("/collectStoreStatus")
    @Operation(summary = "获取收藏店铺状态")
    public Result<Boolean> getCollectStoreStatus(Long storeId){
        boolean status = collectService.getCollectStoreStatus(storeId);
        return Result.ok(status);
    }
}